package com.lovo.sgproj.service.imp;

import com.lovo.sgproj.bean.ClassBean;
import com.lovo.sgproj.dao.ClassDAO;
import com.lovo.sgproj.dao.StudentDAO;
import com.lovo.sgproj.dao.imp.ClassDAOImp;
import com.lovo.sgproj.dao.imp.StudentDAOImp;
import com.lovo.sgproj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class ClassServiceImp implements ClassService {

    @Autowired
    StudentDAO stuDAO ;
    @Autowired
    ClassDAO classDAO ;

    @Override
    public ArrayList<ClassBean> getAllClass() {
        return classDAO.findAllClass();
    }

    @Override
    public boolean addClass(ClassBean theClass) {
        if (classDAO.getClassByName(theClass.getClassName()) == null) {
            classDAO.insertClass(theClass);
            return true;
        }
        return false;
    }

    @Override
    public boolean removeClass(int classId) {
        if (stuDAO.findStudentByClassID(classId).size() == 0) {
            classDAO.deleteClassByID(classId);
            return true;
        }
        return false;
    }
}
